package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Name;
import org.akomantoso.core.data.group.ANsemanticInline;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element entity is a generic inline element to identify a text fragment introducing or referring to a concept in
 * the ontology.
 * 
 * <pre>
 * 	<xsd:element name="entity">
 * 		<xsd:complexType mixed="true">
 * 			<xsd:complexContent>
 * 				<xsd:extension base="inlinereqreq">
 * 					<xsd:attributeGroup ref="name"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class Entity extends InlineReqReqType implements Name, ANsemanticInline {

	public static final String ELEMENT = "entity";

	private String _name;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Name#getName()
	 */
	@Override
	public String getName() {
		return _name;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Name#setName(java.lang.String)
	 */
	@Override
	public void setName(String name) {
		_name = name;
	}

	/**
	 * @see org.akomantoso.core.data.MixedContent#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <E extends Output> void writeExternal(E out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeName(out, this);
		super.writeExternal(out);
		out.writeEnd();
	}

	
	/**
	 * @see org.akomantoso.core.data.InlineReqReqType#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <E extends Input> void readExternal(E in) throws IOException {
		_name = in.readAttribute(Name.ATTRIBUTE);
		super.readExternal(in);
	}

	/**
	 * @see ec.ep.visitor.AKVisitable#accept(ec.ep.visitor.AKVisitor)
	 */
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);
		}
	}

}